package com.wsm.kotlintest.activity

import android.widget.TableLayout
import androidx.fragment.app.transaction
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.wsm.kotlintest.adapter.MainViewPagerAdapter
import com.wsm.kotlintest.fragment.DataFragment
import com.wsm.kotlintest.kotlintest2.R
import com.wsm.kotlintest.kotlintest2.databinding.ActivityMainBinding
import com.wsm.kotlintest.viewmodel.activity.MainActivityViewModel


class MainActivity : BaseActivity<ActivityMainBinding, MainActivityViewModel>(MainActivityViewModel::class.java) {
    override fun doSomething() {
        val pagerAdapter = MainViewPagerAdapter(supportFragmentManager).apply {
            dataList = ArrayList<DataFragment>().apply {
                for (i in 0..2) {
                    add(DataFragment())
                }
            }
        }
        val viewPager: ViewPager = findViewById(R.id.vp_main)
        val tabLayout: TabLayout = findViewById(R.id.tab_layout)
        viewPager.adapter = pagerAdapter
        viewPager.offscreenPageLimit=3
        tabLayout.setupWithViewPager(viewPager)
    }

    override fun inject() {
        binding?.vm = viewModel
    }

    override fun setLayout(): Int {
        return R.layout.activity_main
    }

//    private fun initFragment() {
//        supportFragmentManager.transaction(allowStateLoss = true) { replace(R.id.content, DataFragment.newInstance()) }
//    }

}
